function unistall 

%UNISTALL 
%
%   UNISTALL crack targetlink calibration tool unistallation 
%
%   Inputs:
%       -- / --
%
%   Outputs:
%       -- / --
%
%   Syntax:
%       unistall
%
%   Example:
%       -- / --
%
%   See also:
%       -- / --
% 
%   Author(s): Xiaobiao Huang
%   Copyright 2013-2020 The Xiaobiao Studio.
%   $Revision: 1.0.0.0 $  $Date: 17-Sep-2013 22:46:21 $

fileList = {'tl_open_blockdlg','tl_manage_doc_ctrls'};
% fileList = {'demo','demo2'};

%% recreate tl_open_blockdlg.m
filePath = which(fileList{1});
delete([fileparts(filePath) '\xscrack.p']);
try
    fid = fopen(filePath,'r+');
    tline = fgets(fid);
    iColumn = 1;
    while ischar(tline)
        farray{iColumn,1} = tline;
        if strfind(tline,'% crack the targetlink calibration')
            removeLineStart = iColumn;
        end
        if strfind(tline,'% end of add crack function')
            removeLineEnd = iColumn;
        end
        iColumn = iColumn + 1;
        tline = fgets(fid);
    end
    newfile = [farray(1:removeLineStart-1); farray(removeLineEnd+2:end)];
    fclose(fid);
    % create new file
    fid = fopen(filePath,'w+');
    for iline = 1 : length(newfile)
        fwrite(fid,newfile{iline});
    end
catch exception
    fprintf('remove installation from  %s failed: %s\n',fileList{1}, exception.message);
    return;
end
fprintf('remove installation from %s successed\n',fileList{1});

%% recreate tl_manage_doc_ctrls.m
filePath = which(fileList{2});
try
    fid = fopen(filePath,'r+');
    tline = fgets(fid);
    iColumn = 1;
    while ischar(tline)
        farray{iColumn,1} = tline;
        if strfind(tline,'% add a crack button in the figure panel')
            removeLineStart = iColumn;
        end
        if strfind(tline,'% end of add crack button')
            removeLineEnd = iColumn;
        end
        if strfind(tline,'function crackdlg(obj,env)')
            removeLineStart2 = iColumn;
        end
        iColumn = iColumn + 1;
        tline = fgets(fid);
    end
    newfile = [farray(1:removeLineStart-1); farray(removeLineEnd+2:removeLineStart2-1)];
    fclose(fid);
    % create new file
    fid = fopen(filePath,'w+');
    for iline = 1 : length(newfile)
        fwrite(fid,newfile{iline});
    end
catch exception
    fclose(fid);
    fprintf('remove installation from  %s failed: %s\n',fileList{2}, exception.message);
    return;
end

fprintf('remove installation from %s successed\n',fileList{2});
end % end of function  unistall
